home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS Toolkit
/
BBS Toolkit.iso
/
doors_1
/
icomblt5.zip
/
REPLACE.DOC
< prev
next >
Wrap
Text File
|
1986-07-07
|
12KB
|
361 lines
REPLACE 3.0 July 1, 1986
DESCRIPTION:
===========
REPLACE is a general purpose MS-DOS filter that reads a sequential input
file, replaces specified strings with new strings, and writes the result
to a new sequential file. It reads the input file from standard in, and
sends the output file to standard out. This allows it to be used with
MS-DOS piping. It is driven by a control file and produces a small
report of statistics or errors back to the standard error device,
normally the terminal. It supports both character and hex input for the
old and new strings.
(C) Copyright 1986 by Bill Prew, ALL RIGHTS RESERVED
Please refer all inquiries to:
Bill Prew
1615 Pawtucket Ave
Rumford RI 02916
You may copy and distribute this program freely, provided that:
<1> No fee is charged for such copying and distribution, and
<2> It is distributed ONLY in its original, unmodified state.
This program is being distributed as user supported software. If you
like this program, and find it of use, then your contribution will be
appreciated. If you are using this product in a commercial environment,
then the contribution is not voluntary. If you would like the source for
the program send a mailer and $10 to the address above with a formatted
floppy.
USAGE:
=====
The command format to execute the program is;
REPLACE <input-filename >output-filename control-filename
where input-filename is the input file, output-filename is the newly
created file after all replace commands have been applied, and
control-filename is the name of the file that contains the replace
commands and options.
CONTROL CARD FORMATS:
====================
The general format of the control cards is;
type,parms
where type can be "opts", "text" or "hex" as discussed below, and parms
are different parameters and information needed by the different control
cards.
Page 1
REPLACE 3.0 July 1, 1986
"OPTS" CONTROL CARD:
-------------------
This card selects several options for the run with the format;
opts,[pad | nopad , one | all]
pad ............... this preserves trailing spaces in the output
records.
nopad ............. this causes all trailing spaces to be eliminated
from the output records before they are written
(this is the default).
one ............... this option forces the program to only scan
forward on the line after each replace is
performed.
all ............... this causes the entire line to be re-scanned
after each replace is performed (this is the
default).
"TEXT" CONTROL CARD:
--------------------
This is the most used card in replace control files and specifies an
old string to be replaced by a new string. The strings can be
different lengths and the new string can be a 'null' string to cause
deletion of the old string. The format is;
text,'old-string'[new-string]'
' ................. notice the three single quotes in the parms.
this is the delimiter and bounds the new and old
strings. it can be any character, as long as all
three are the same.
old-string ........ this is the target string you want to replace.
new-string ........ this is new string to substitute for the old
string. if omitted the old string will be
deleted.
"HEX" CONTROL CARD:
-------------------
This card is very similar to the "text" card except it allows you to
specify the old and new strings as hex data. The format is;
hex,old-hex-string,[new-hex-string]
old-hex-string .... this is the target string you want to replace, in
hex format. for example 414243 would replace ABC
in the input file.
Page 2
REPLACE 3.0 July 1, 1986
new-hex-string .... this is new string to substitute for the old
string in hex format. if omitted the old string
will be deleted.
EXAMPLES:
=========
EXAMPLE 1:
----------
REPLACE <in >out replace.ctl
replace.ctl ....... text,'XXXX'YYYY'
text,'ZZZZ''
hex,30,2d
in ................ 0123456789
XXXXXXXX
XXXXZZZZ
out ............... -123456789
YYYYYYYY
YYYY
This is pretty straight forward, all "XXXX" were replaced by "YYYY",
all "ZZZZ" were deleted, and hex "30" was replaced by "2d".
EXAMPLE 2:
----------
REPLACE <in >out replace.ctl
replace.ctl ....... opts,all
text,'XXXX'YYXX'
in ................ XXXXXXXX
out ............... YYYYYYXX
This is a little trickier. I have shown the "opts,all" for clarity,
even though the same results would occur if it was left out, as it is
the default. Notice that the line was transformed from "XXXXXXXX" to
"YYYYYYXX" as below;
"XXXXXXX" -> "YYXXXXXX" -> "YYYYXXXX" -> "YYYYYYXX"
This illustrates how the entire line is re-scanned after each replace
is performed. The next example contrasts this with the "one" option.
EXAMPLE 3:
----------
REPLACE <in >out replace.ctl
Page 3
REPLACE 3.0 July 1, 1986
replace.ctl ....... opts,one
text,'XXXX'YYXX'
in ................ XXXXXXXX
out ............... YYXXYYXX
Notice that the results here are different since only the remaining
part of the line is re-scanned after each replace. Notice that the
line was transformed from "XXXXXXXX" to "YYXXYYXX" as below;
"XXXXXXX" -> "YYXXXXXX" -> "YYXXYYXX"
EXAMPLE 4:
----------
FILATR a: | REPLACE >out replace.ctl
replace.ctl ....... text,' A ' Modified, '
text,' S ' System, '
text,' R ' Read-only, '
text,' H ' Hidden, '
text,' .''
FILATR output ..... MS-DOS File Attribute Utility version 2.12
loader.sys . S R H .
io.sys . S R H .
msdos.sys . S R H .
command.com . . . . .
config.sys A . . . .
autoexec.bat . . . . .
6 files
out ............... MS-DOS File Attribute Utility version 2.12
loader.sys System, Read-only, Hidden,
io.sys System, Read-only, Hidden,
msdos.sys System, Read-only, Hidden,
command.com
config.sys Modified,
autoexec.bat
6 files
This example demonstrates the support of piping to pass the output
from one command into the REPLACE program.
NOTES:
=====
<1> Each record from the input file is read once, and then all
replaces are applied to it, in the order they were specified. The
Page 4
REPLACE 3.0 July 1, 1986
order of the control cards can be very important if the results of
one replace affect another one.
<2> The replace procedure is recursive in nature so that when a
record is read, and a change applied, the changed record is then
checked to see if another change is required (starting at the first
position of the record). if the all option is active, or picking up
at the end of the replaced string if the one option is active).
<3> By using 'con' (without the quotes) as the control-filename on
the command line you can enter the control cards from the keyboard
and terminate them with a ctl-Z. This is convenient for one time
quicky runs.
LIMITS:
======
Maximum input/output record length = 2000 bytes
Maximum number of control cards = 100
Maximum length of strings on 'text'/'hex' control cards = 100 bytes
Binary data is supported with the exception of line-feed chars, as
these are used as in MS-DOS to end logical records in the sequential
file.
RELEASE INFO:
============
RELEASE 3.0
<1> The program was completely re-written using Lattice version 3.0
for speed and added flexibility. This release runs 3 to 10 times
faster than release 2.0.
<2> The program was changed to support MS-DOS redirection and piping
for it's input and output filenames. It now reads it's input from
Standard Input and writes it's output to Standard Output.
<3> The program now supports record lengths up to 2000 characters in
length.
<4> The control card format was changed slightly to allow any
character to be used as the text string delimiter. This allows
double quotes to be part of the replace strings by using some other
delimiter character.
<5> An option switch was added to allow specify 'one' or 'all'
replace modes. See the detail documentation for further info.
RELEASE 2.0
Page 5
REPLACE 3.0 July 1, 1986
<1> The statistics are now displayed directly to the screen instead
of being written to the REPLACE.PRN file.
<2> The control file name no longer has to be REPLACE.CTL. Any
filename can be entered on the command line such as "REPLACE
TEST.CTL". If no name is entered, REPLACE.CTL is still used by
default.
<3> The program has been re-written a bit and now runs in almost half
the time of the initial version.
<4> Error reporting has been greatly improved.
<5> A check is made to determine if the replacement string contains
the source string. This eliminates the chance of an infinite loop.
RELEASE 1.0
<1> This was the initial release.
Page 6